@using Elsa.Studio.Models
@using Elsa.Api.Client.Resources.Scripting.Models

@{
    var inputDescriptor = EditorContext.InputDescriptor;
    var displayName = inputDescriptor.DisplayName;
    var description = inputDescriptor.Description;
    var inputValue = EditorContext.GetLiteralValueOrDefault();
}

<ExpressionInput EditorContext="@EditorContext">
    <ChildContent>
        <MudTextField
            T="string"
            Label="@displayName"
            Variant="Variant.Outlined"
            HelperText="@description"
            Margin="Margin.Dense"
            ReadOnly="EditorContext.IsReadOnly"
            Value="@inputValue"
            ValueChanged="OnValueChanged"/>
    </ChildContent>
</ExpressionInput>

@code {

    [Parameter]
    public DisplayInputEditorContext EditorContext { get; set; } = default!;

    private async Task OnValueChanged(string newValue)
    {
        var expression = Expression.CreateLiteral(newValue);
        
        await EditorContext.UpdateExpressionAsync(expression);
    }

}